home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / gepackte_disketten / 1994 / 08_94_5.dms / 08_94_5.adf / term-4.0-Source.lha / termConfig.c < prev    next >
C/C++ Source or Header  |  1994-07-15  |  54KB  |  2,366 lines

  1. /*
  2. **    termConfig.c
  3. **
  4. **    Configuration processing routines
  5. **
  6. **    Copyright © 1990-1994 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Number of chunks to stop at. */
  13.  
  14. #define    NUM_STOPS    19
  15.  
  16.     /* Reset routine function pointer. */
  17.  
  18. typedef VOID        (* RESET)(APTR,STRPTR);
  19.  
  20.     /* Local routines. */
  21.  
  22. STATIC BYTE        ReadSerialPrefs(struct SerialPrefs *Prefs);
  23.  
  24. STATIC VOID        ResetSerialConfig(struct SerialSettings *SerialConfig);
  25. STATIC VOID        ResetModem(struct ModemSettings *ModemConfig);
  26. STATIC VOID        ResetScreen(struct ScreenSettings *ScreenConfig);
  27. STATIC VOID        ResetTerminal(struct TerminalSettings *TerminalConfig);
  28. STATIC VOID        ResetEmulation(struct EmulationSettings *EmulationConfig);
  29. STATIC VOID        ResetClip(struct ClipSettings *ClipConfig);
  30. STATIC VOID        ResetCapture(struct CaptureSettings *CaptureConfig);
  31. STATIC VOID        ResetFile(struct FileSettings *FileConfig,STRPTR PathBuffer);
  32. STATIC VOID        ResetPath(struct PathSettings *PathConfig,STRPTR PathBuffer);
  33. STATIC VOID        ResetMisc(struct MiscSettings *MiscConfig);
  34. STATIC VOID        ResetCommand(struct CommandSettings *CommandConfig);
  35. STATIC VOID        ResetTransfer(struct TransferSettings *TransferConfig,STRPTR DefaultLib);
  36.  
  37. STATIC BYTE        WriteConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,BYTE Type,APTR TempBuffer,STRPTR Password);
  38. STATIC BYTE        WriteConfigChunks(struct IFFHandle *Handle,struct Configuration *Config,APTR TempBuffer,STRPTR Password);
  39. STATIC UBYTE        IsConfigChunk(ULONG ID);
  40. STATIC BYTE        ReadConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,UBYTE Type,LONG Len,STRPTR Password);
  41.  
  42. STATIC UWORD SizeTable[] =
  43. {
  44.     sizeof(struct SerialSettings),
  45.     sizeof(struct ModemSettings),
  46.     sizeof(struct CommandSettings),
  47.     sizeof(struct ScreenSettings),
  48.     sizeof(struct TerminalSettings),
  49.     sizeof(struct PathSettings),
  50.     sizeof(struct MiscSettings),
  51.     sizeof(struct ClipSettings),
  52.     sizeof(struct CaptureSettings),
  53.     sizeof(struct FileSettings),
  54.     sizeof(struct EmulationSettings),
  55.     sizeof(struct TransferSettings)
  56. };
  57.  
  58. STATIC RESET ResetTable[] =
  59. {
  60.     (RESET)ResetSerialConfig,
  61.     (RESET)ResetModem,
  62.     (RESET)ResetCommand,
  63.     (RESET)ResetScreen,
  64.     (RESET)ResetTerminal,
  65.     ResetPath,
  66.     (RESET)ResetMisc,
  67.     (RESET)ResetClip,
  68.     (RESET)ResetCapture,
  69.     ResetFile,
  70.     (RESET)ResetEmulation,
  71.     ResetTransfer
  72. };
  73.  
  74. STATIC ULONG TypeTable[] =
  75. {
  76.     ID_SERL,
  77.     ID_MODM,
  78.     ID_COMD,
  79.     ID_SCRN,
  80.     ID_TRML,
  81.     ID_PATH,
  82.     ID_MISC,
  83.     ID_CLIP,
  84.     ID_CPTR,
  85.     ID_FILE,
  86.     ID_EMLN,
  87.     ID_XFER
  88. };
  89.  
  90. STATIC ULONG Stops[NUM_STOPS * 2] =
  91. {
  92.     ID_TERM,ID_CAT,
  93.     ID_TERM,ID_VERS,
  94.     ID_TERM,ID_DIAL,
  95.     ID_TERM,ID_DATE,
  96.     ID_TERM,ID_PHON,
  97.     ID_TERM,ID_PSWD,
  98.  
  99.     ID_TERM,ID_SERL,
  100.     ID_TERM,ID_MODM,
  101.     ID_TERM,ID_COMD,
  102.     ID_TERM,ID_SCRN,
  103.     ID_TERM,ID_TRML,
  104.     ID_TERM,ID_PATH,
  105.     ID_TERM,ID_MISC,
  106.     ID_TERM,ID_CLIP,
  107.     ID_TERM,ID_CPTR,
  108.     ID_TERM,ID_FILE,
  109.     ID_TERM,ID_EMLN,
  110.     ID_TERM,ID_XFER,
  111.     ID_TERM,ID_WINF
  112. };
  113.  
  114. STATIC VOID __regargs
  115. FixOldConfig(struct Configuration *Config,UBYTE ConfigChunkType,BOOLEAN IsPhonebook)
  116. {
  117.     if(ConfigChunkType == PREF_SERIAL)
  118.         Config -> SerialConfig -> UseOwnDevUnit = TRUE;
  119.  
  120.     if(ConfigChunkType == PREF_SCREEN)
  121.     {
  122.         Config -> ScreenConfig -> UsePens    = TRUE;
  123.         Config -> ScreenConfig -> Depth        = 0;
  124.         Config -> ScreenConfig -> PenColourMode    = 42;    // Avoid trouble
  125.     }
  126.  
  127.     if(ConfigChunkType == PREF_TRANSFER)
  128.         Config -> TransferConfig -> MangleFileNames = FALSE;
  129.  
  130.     if(ConfigChunkType == PREF_MODEM)
  131.         Config -> ModemConfig -> AbortHangsUp = FALSE;
  132.  
  133.     if(ConfigChunkType == PREF_COMMAND && IsPhonebook)
  134.     {
  135.         strcpy(Config -> CommandConfig -> LoginMacro,Config -> CommandConfig -> StartupMacro);
  136.  
  137.         memset(Config -> CommandConfig -> StartupMacro,0,sizeof(Config -> CommandConfig -> StartupMacro));
  138.     }
  139.  
  140.     if(ConfigChunkType == PREF_CAPTURE)
  141.         Config -> CaptureConfig -> SearchHistory = 10;
  142.  
  143.     if(ConfigChunkType == PREF_EMULATION)
  144.     {
  145.         if(Config -> EmulationConfig -> DestructiveBackspace < 0 || Config -> EmulationConfig -> DestructiveBackspace > 2)
  146.             Config -> EmulationConfig -> DestructiveBackspace = 1;
  147.     }
  148. }
  149.  
  150. VOID __regargs
  151. FixScreenPens(struct ScreenSettings *ScreenConfig)
  152. {
  153.     WORD i,Count;
  154.  
  155.     for(Count = 0, i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  156.     {
  157.         if(ScreenConfig -> PenArray[i])
  158.             Count++;
  159.     }
  160.  
  161.     if(!Count)
  162.         ScreenConfig -> UsePens = TRUE;
  163. }
  164.  
  165.     /* ReadSerialPrefs():
  166.      *
  167.      *    Reads the default serial preferences settings.
  168.      */
  169.  
  170. STATIC BYTE
  171. ReadSerialPrefs(struct SerialPrefs *Prefs)
  172. {
  173.     struct IFFHandle    *Handle;
  174.     BYTE             Success = FALSE;
  175.     LONG             Error = 0;
  176.  
  177.         /* Allocate an IFF handle. */
  178.  
  179.     if(Handle = AllocIFF())
  180.     {
  181.             /* Open the preferences settings file. */
  182.  
  183.         if(Handle -> iff_Stream = Open("ENV:sys/serial.prefs",MODE_OLDFILE))
  184.         {
  185.                 /* Make it known as a DOS file handle. */
  186.  
  187.             InitIFFasDOS(Handle);
  188.  
  189.                 /* Open the file for reading. */
  190.  
  191.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  192.             {
  193.                     /* Stop at the `body' chunk. */
  194.  
  195.                 if(!(Error = StopChunk(Handle,ID_PREF,ID_SERL)))
  196.                 {
  197.                         /* Look for it... */
  198.  
  199.                     if(!ParseIFF(Handle,IFFPARSE_SCAN))
  200.                     {
  201.                             /* Read the data. */
  202.  
  203.                         if(ReadChunkBytes(Handle,Prefs,sizeof(struct SerialPrefs)) == sizeof(struct SerialPrefs))
  204.                             Success = TRUE;
  205.                         else
  206.                             Error = IoErr();
  207.                     }
  208.                 }
  209.  
  210.                     /* Close the handle. */
  211.  
  212.                 CloseIFF(Handle);
  213.             }
  214.  
  215.                 /* Release the handle. */
  216.  
  217.             Close(Handle -> iff_Stream);
  218.         }
  219.         else
  220.             Error = IoErr();
  221.  
  222.             /* Clean up. */
  223.  
  224.         FreeIFF(Handle);
  225.     }
  226.     else
  227.         Error = ERR_NO_MEM;
  228.  
  229.     if(Error)
  230.         SetIoErr(Error);
  231.  
  232.         /* Return sucess/failure. */
  233.  
  234.     return(Success);
  235. }
  236.  
  237. STATIC VOID
  238. ResetSerialConfig(struct SerialSettings *SerialConfig)
  239. {
  240.     STATIC BYTE            SerialPrefsRead        = FALSE,
  241.                     SerialPrefsReadFailed    = FALSE;
  242.     STATIC struct SerialPrefs    SerialPrefs;
  243.  
  244.         /* The program will only try to read the preferences
  245.          * settings once; if the first access failed, no
  246.          * other accesses will be made.
  247.          */
  248.  
  249.     if(!SerialPrefsRead && !SerialPrefsReadFailed)
  250.         SerialPrefsReadFailed = ReadSerialPrefs(&SerialPrefs) ^ TRUE;
  251.  
  252.         /* Did we succeed in reading the file? */
  253.  
  254.     if(!SerialPrefsRead)
  255.     {
  256.         SerialConfig -> BaudRate        = 2400;
  257.         SerialConfig -> BitsPerChar        = 8;
  258.         SerialConfig -> Parity            = PARITY_NONE;
  259.         SerialConfig -> StopBits        = 1;
  260.         SerialConfig -> HandshakingProtocol    = HANDSHAKING_NONE;
  261.         SerialConfig -> xONxOFF            = TRUE;
  262.         SerialConfig -> SerialBufferSize    = 32768;
  263.     }
  264.     else
  265.     {
  266.             /* Fill in the common data. */
  267.  
  268.         SerialConfig -> BaudRate        = SerialPrefs . sp_BaudRate;
  269.         SerialConfig -> SerialBufferSize    = SerialPrefs . sp_InputBuffer;
  270.         SerialConfig -> BitsPerChar        = SerialPrefs . sp_BitsPerChar;
  271.         SerialConfig -> StopBits        = SerialPrefs . sp_StopBits;
  272.  
  273.             /* Convert the handshaking mode. */
  274.  
  275.         switch(SerialPrefs . sp_InputHandshake)
  276.         {
  277.             case HSHAKE_NONE:
  278.  
  279.                 SerialConfig -> HandshakingProtocol    = HANDSHAKING_NONE;
  280.                 SerialConfig -> xONxOFF            = FALSE;
  281.  
  282.                 break;
  283.  
  284.             case HSHAKE_RTS:
  285.  
  286.                 SerialConfig -> HandshakingProtocol    = HANDSHAKING_RTSCTS;
  287.                 SerialConfig -> xONxOFF            = FALSE;
  288.  
  289.                 break;
  290.  
  291.             default:
  292.  
  293.                 SerialConfig -> HandshakingProtocol    = HANDSHAKING_NONE;
  294.                 SerialConfig -> xONxOFF            = TRUE;
  295.  
  296.                 break;
  297.         }
  298.  
  299.             /* Convert the parity settings. */
  300.  
  301.         if(SerialPrefs . sp_Parity <= PARITY_SPACE)
  302.             SerialConfig -> Parity = SerialPrefs . sp_Parity;
  303.         else
  304.             SerialConfig -> Parity = PARITY_NONE;
  305.  
  306.         SerialPrefsRead = TRUE;
  307.     }
  308.  
  309.     strcpy(SerialConfig -> SerialDevice,SERIALNAME);
  310.  
  311.     SerialConfig -> Duplex        = DUPLEX_FULL;
  312.     SerialConfig -> HighSpeed    = FALSE;
  313.     SerialConfig -> Shared        = FALSE;
  314.     SerialConfig -> BreakLength    = 250000;
  315.     SerialConfig -> UnitNumber    = 0;
  316.     SerialConfig -> StripBit8    = FALSE;
  317.     SerialConfig -> CheckCarrier    = FALSE;
  318.     SerialConfig -> PassThrough    = FALSE;
  319.     SerialConfig -> IgnoreCarrier    = FALSE;
  320.  
  321.     SerialConfig -> Quantum        = 256;
  322.  
  323.     SerialConfig -> UseNet        = FALSE;
  324.     SerialConfig -> NetID        = 0002;
  325. }
  326.  
  327. STATIC VOID
  328. ResetModem(struct ModemSettings *ModemConfig)
  329. {
  330.     strcpy(ModemConfig -> ModemInit,    "ATZ\\r");
  331.     strcpy(ModemConfig -> ModemExit,    "");
  332.     strcpy(ModemConfig -> ModemHangup,    "~~~~~~~~+++~~~~~~ATH0\\r");
  333.     strcpy(ModemConfig -> DialPrefix,    "~~ATDP");
  334.     strcpy(ModemConfig -> DialSuffix,    "\\r");
  335.  
  336.     strcpy(ModemConfig -> NoCarrier,    "NO CARRIER");
  337.     strcpy(ModemConfig -> NoDialTone,    "NO DIALTONE");
  338.     strcpy(ModemConfig -> Connect,        "CONNECT");
  339.     strcpy(ModemConfig -> Voice,        "VOICE");
  340.     strcpy(ModemConfig -> Ring,        "RING");
  341.     strcpy(ModemConfig -> Busy,        "BUSY");
  342.     strcpy(ModemConfig -> Ok,        "OK");
  343.     strcpy(ModemConfig -> Error,        "ERROR");
  344.  
  345.     ModemConfig -> RedialDelay        = 2;
  346.     ModemConfig -> DialRetries        = 10;
  347.     ModemConfig -> DialTimeout        = 60;
  348.     ModemConfig -> ConnectAutoBaud        = FALSE;
  349.     ModemConfig -> DropDTR            = FALSE;
  350.     ModemConfig -> RedialAfterHangup    = FALSE;
  351.  
  352.     ModemConfig -> NoCarrierIsBusy        = TRUE;
  353.  
  354.     ModemConfig -> ConnectLimit        = 0;
  355.     ModemConfig -> ConnectLimitMacro[0]    = 0;
  356.  
  357.     ModemConfig -> TimeToConnect        = 0;
  358. }
  359.  
  360. STATIC VOID
  361. ResetScreen(struct ScreenSettings *ScreenConfig)
  362. {
  363.     memset(ScreenConfig,0,sizeof(struct ScreenSettings));
  364.  
  365.     ScreenConfig -> DisplayMode        = DEFAULT_MONITOR_ID|HIRES_KEY;
  366.     ScreenConfig -> ColourMode        = COLOUR_AMIGA;
  367.     ScreenConfig -> MakeScreenPublic    = TRUE;
  368.     ScreenConfig -> ShanghaiWindows        = FALSE;
  369.     ScreenConfig -> TitleBar        = TRUE;
  370.     ScreenConfig -> StatusLine        = STATUSLINE_STANDARD;
  371.     ScreenConfig -> Blinking        = TRUE;
  372.     ScreenConfig -> FasterLayout        = FALSE;
  373.     ScreenConfig -> UseWorkbench        = FALSE;
  374.  
  375.     strcpy(ScreenConfig -> FontName,"topaz.font");
  376.     ScreenConfig -> FontHeight = 8;
  377.  
  378.     ScreenConfig -> PubScreenName[0]    = 0;
  379.     ScreenConfig -> TimeMode        = ONLINETIME_BOTH;
  380.     ScreenConfig -> UsePens            = TRUE;
  381.     ScreenConfig -> PenColourMode        = COLOUR_AMIGA;
  382.  
  383.     ScreenConfig -> DisplayWidth        = 0;
  384.     ScreenConfig -> DisplayHeight        = 0;
  385.     ScreenConfig -> OverscanType        = OSCAN_TEXT;
  386.  
  387.     ScreenConfig -> ShareScreen        = FALSE;
  388.     ScreenConfig -> SplitStatus        = FALSE;
  389. }
  390.  
  391. STATIC VOID
  392. ResetTerminal(struct TerminalSettings *TerminalConfig)
  393. {
  394.     TerminalConfig -> BellMode        = BELL_AUDIBLE;
  395.     TerminalConfig -> AlertMode        = ALERT_BEEP_SCREEN;
  396.     TerminalConfig -> EmulationMode        = EMULATION_ANSIVT100;
  397.     TerminalConfig -> FontMode        = FONT_STANDARD;
  398.  
  399.     TerminalConfig -> SendCR        = CR_ASCR;
  400.     TerminalConfig -> SendLF        = LF_ASLF;
  401.     TerminalConfig -> ReceiveCR        = CR_ASCR;
  402.     TerminalConfig -> ReceiveLF        = LF_ASLF;
  403.  
  404.     TerminalConfig -> NumColumns        = 0;
  405.     TerminalConfig -> NumLines        = 0;
  406.  
  407.     TerminalConfig -> KeyMapFileName[0]    = 0;
  408.     TerminalConfig -> EmulationFileName[0]    = 0;
  409.     TerminalConfig -> BeepFileName[0]    = 0;
  410.  
  411.     strcpy(TerminalConfig -> TextFontName,"topaz.font");
  412.     TerminalConfig -> TextFontHeight = 8;
  413.  
  414.     TerminalConfig -> UseTerminalTask = FALSE;
  415.     TerminalConfig -> Pad = 0;
  416.  
  417.     strcpy(TerminalConfig -> IBMFontName,"IBM.font");
  418.     TerminalConfig -> IBMFontHeight = 8;
  419. }
  420.  
  421. STATIC VOID
  422. ResetEmulation(struct EmulationSettings *EmulationConfig)
  423. {
  424.     EmulationConfig -> CursorMode        = KEYMODE_STANDARD;
  425.     EmulationConfig -> NumericMode        = KEYMODE_STANDARD;
  426.  
  427.     EmulationConfig -> NewLineMode        = FALSE;
  428.     EmulationConfig -> InsertMode        = FALSE;
  429.  
  430.     EmulationConfig -> LineWrap        = TRUE;
  431.     EmulationConfig -> CursorWrap        = FALSE;
  432.  
  433.     EmulationConfig -> FontScale        = SCALE_NORMAL;
  434.     EmulationConfig -> ScrollMode        = SCROLL_JUMP;
  435.     EmulationConfig -> DestructiveBackspace    = FALSE;
  436.     EmulationConfig -> SwapBSDelete        = FALSE;
  437.     EmulationConfig -> PrinterEnabled    = TRUE;
  438.     EmulationConfig -> AnswerBack[0]    = 0;
  439.     EmulationConfig -> CLSResetsCursor    = 0;
  440.  
  441.     EmulationConfig -> KeysLocked        = FALSE;
  442.     EmulationConfig -> MaxScroll        = 0;
  443.     EmulationConfig -> MaxJump        = 1;
  444.     EmulationConfig -> CursorLocked        = FALSE;
  445.     EmulationConfig -> FontLocked        = FALSE;
  446.     EmulationConfig -> Pad            = 0;
  447. }
  448.  
  449. STATIC VOID
  450. ResetClip(struct ClipSettings *ClipConfig)
  451. {
  452.     ClipConfig -> ClipboardUnit    = 0;
  453.     ClipConfig -> LineDelay        = 0;
  454.     ClipConfig -> CharDelay        = 0;
  455.  
  456.     ClipConfig -> InsertPrefix[0] = 0;
  457.     strcpy(ClipConfig -> InsertSuffix,"\\r");
  458.  
  459.     ClipConfig -> LinePrompt[0]    = 0;
  460.     ClipConfig -> SendTimeout    = 0;
  461.     ClipConfig -> PacingMode    = PACE_DIRECT;
  462. }
  463.  
  464. STATIC VOID
  465. ResetCapture(struct CaptureSettings *CaptureConfig)
  466. {
  467.     CaptureConfig -> LogActions        = FALSE;
  468.     CaptureConfig -> LogCall        = FALSE;
  469.     CaptureConfig -> LogFileName[0]        = 0;
  470.  
  471.     CaptureConfig -> MaxBufferSize        = 0;
  472.     CaptureConfig -> BufferEnabled        = TRUE;
  473.  
  474.     CaptureConfig -> ConnectAutoCapture    = FALSE;
  475.     CaptureConfig -> CaptureFilterMode    = FILTER_BOTH;
  476.     CaptureConfig -> CapturePath[0]        = 0;
  477.  
  478.     CaptureConfig -> CallLogFileName[0]    = 0;
  479.     CaptureConfig -> BufferPath[0]        = 0;
  480.  
  481.     CaptureConfig -> AutoCaptureDate    = AUTOCAPTURE_DATE_NAME;
  482.     CaptureConfig -> SearchHistory        = 10;
  483.  
  484.     CaptureConfig -> OpenBufferWindow    = BUFFER_END;
  485.     CaptureConfig -> OpenBufferScreen    = BUFFER_TOP;
  486.     CaptureConfig -> BufferScreenPosition    = SCREEN_CENTRE;
  487.     CaptureConfig -> BufferWidth        = 80;
  488.  
  489.     CaptureConfig -> RememberBufferWindow    = FALSE;
  490.     CaptureConfig -> RememberBufferScreen    = FALSE;
  491.  
  492.     CaptureConfig -> BufferScreenMode    = INVALID_ID;
  493. }
  494.  
  495. STATIC VOID
  496. ResetFile(struct FileSettings *FileConfig,STRPTR PathBuffer)
  497. {
  498.     if(!PathBuffer)
  499.         PathBuffer = "TERM:config";
  500.  
  501.     strcpy(FileConfig -> ProtocolFileName,"xprzmodem.library");
  502.  
  503.     if(!LastTranslation[0])
  504.     {
  505.         strcpy(LastTranslation,PathBuffer);
  506.  
  507.         AddPart(LastTranslation,"translation.prefs",MAX_FILENAME_LENGTH);
  508.     }
  509.  
  510.     strcpy(FileConfig -> TranslationFileName,LastTranslation);
  511.  
  512.     if(!LastMacros[0])
  513.     {
  514.         strcpy(LastMacros,PathBuffer);
  515.  
  516.         AddPart(LastMacros,"functionkeys.prefs",MAX_FILENAME_LENGTH);
  517.     }
  518.  
  519.     strcpy(FileConfig -> MacroFileName,LastMacros);
  520.  
  521.     if(!LastFastMacros[0])
  522.     {
  523.         strcpy(LastFastMacros,PathBuffer);
  524.  
  525.         AddPart(LastFastMacros,"fastmacros.prefs",MAX_FILENAME_LENGTH);
  526.     }
  527.  
  528.     strcpy(FileConfig -> FastMacroFileName,LastFastMacros);
  529.  
  530.     if(!LastCursorKeys[0])
  531.     {
  532.         strcpy(LastCursorKeys,PathBuffer);
  533.  
  534.         AddPart(LastCursorKeys,"cursorkeys.prefs",MAX_FILENAME_LENGTH);
  535.     }
  536.  
  537.     strcpy(FileConfig -> CursorFileName,LastCursorKeys);
  538. }
  539.  
  540. STATIC VOID
  541. ResetPath(struct PathSettings *PathConfig,STRPTR PathBuffer)
  542. {
  543.     if(!PathBuffer)
  544.         PathBuffer = "TERM:config";
  545.  
  546.     strcpy(PathConfig -> DefaultStorage,PathBuffer);
  547.  
  548.     PathConfig -> ASCIIUploadPath[0]    = 0;
  549.     PathConfig -> ASCIIDownloadPath[0]    = 0;
  550.     PathConfig -> TextUploadPath[0]        = 0;
  551.     PathConfig -> TextDownloadPath[0]    = 0;
  552.     PathConfig -> BinaryUploadPath[0]    = 0;
  553.     PathConfig -> BinaryDownloadPath[0]    = 0;
  554.  
  555.     strcpy(PathConfig -> HelpFile,"PROGDIR:term.guide");
  556.  
  557.     strcpy(PathConfig -> DefaultStorage,PathBuffer);
  558.  
  559.     GetEnvDOS(PathConfig -> Editor,"EDITOR");
  560. }
  561.  
  562. STATIC VOID
  563. ResetMisc(struct MiscSettings *MiscConfig)
  564. {
  565.     MiscConfig -> Priority            = 1;
  566.     MiscConfig -> BackupConfig        = FALSE;
  567.  
  568.     MiscConfig -> OpenFastMacroPanel    = FALSE;
  569.     MiscConfig -> ReleaseDevice        = TRUE;
  570.  
  571.     MiscConfig -> TransferServer        = TRUE;
  572.     MiscConfig -> EmulationServer        = TRUE;
  573.  
  574.     MiscConfig -> OverridePath        = TRUE;
  575.     MiscConfig -> AutoUpload        = TRUE;
  576.     MiscConfig -> SetArchivedBit        = FALSE;
  577.     MiscConfig -> IdentifyFiles        = IDENTIFY_FILETYPE;
  578.     MiscConfig -> TransferIcons        = FALSE;
  579.     MiscConfig -> CreateIcons        = FALSE;
  580.     MiscConfig -> SimpleIO            = FALSE;
  581.     MiscConfig -> PerfMeter            = FALSE;
  582.  
  583.     MiscConfig -> IOBufferSize        = 32768;
  584. }
  585.  
  586. STATIC VOID
  587. ResetCommand(struct CommandSettings *CommandConfig)
  588. {
  589.     CommandConfig -> StartupMacro[0]    = 0;
  590.     CommandConfig -> LogoffMacro[0]        = 0;
  591.     CommandConfig -> LoginMacro[0]        = 0;
  592.     CommandConfig -> UploadMacro[0]        = 0;
  593.     CommandConfig -> DownloadMacro[0]    = 0;
  594. }
  595.  
  596. STATIC VOID
  597. ResetTransfer(struct TransferSettings *TransferConfig,STRPTR DefaultLib)
  598. {
  599.     if(!DefaultLib)
  600.         strcpy(TransferConfig -> DefaultLibrary,"xprzmodem.library");
  601.     else
  602.         strcpy(TransferConfig -> DefaultLibrary,DefaultLib);
  603.  
  604.     strcpy(TransferConfig -> ASCIIUploadLibrary,    "xprascii.library");
  605.     strcpy(TransferConfig -> ASCIIDownloadLibrary,    "xprascii.library");
  606.  
  607.     TransferConfig -> TextUploadLibrary[0]        = 0;
  608.     TransferConfig -> TextDownloadLibrary[0]    = 0;
  609.  
  610.     TransferConfig -> BinaryUploadLibrary[0]    = 0;
  611.     TransferConfig -> BinaryDownloadLibrary[0]    = 0;
  612.  
  613.     TransferConfig -> InternalASCIIUpload        = FALSE;
  614.     TransferConfig -> InternalASCIIDownload        = FALSE;
  615.     TransferConfig -> QuietTransfer            = FALSE;
  616.     TransferConfig -> MangleFileNames        = FALSE;
  617.  
  618.     TransferConfig -> LinePrompt[0]            = 0;
  619.     TransferConfig -> SendTimeout            = 0;
  620.     TransferConfig -> PacingMode            = PACE_DIRECT;
  621.     TransferConfig -> StripBit8            = FALSE;
  622.     TransferConfig -> IgnoreDataPastArnold        = TRUE;
  623.     TransferConfig -> TerminatorChar        = 0x1A;
  624.     TransferConfig -> SendCR            = CR_ASCR;
  625.     TransferConfig -> SendLF            = LF_ASLF;
  626.     TransferConfig -> ReceiveCR            = CR_ASCR;
  627.     TransferConfig -> ReceiveLF            = LF_ASLF;
  628. }
  629.  
  630.     /* ResetConfig():
  631.      *
  632.      *    Initialize configuration with default values.
  633.      */
  634.  
  635. VOID __regargs
  636. ResetConfig(struct Configuration *Config,STRPTR PathBuffer)
  637. {
  638.     if(!PathBuffer)
  639.         PathBuffer = "TERM:config";
  640.  
  641.     ResetPath(Config -> PathConfig,PathBuffer);
  642.     ResetFile(Config -> FileConfig,PathBuffer);
  643.  
  644.     ResetSerialConfig(Config -> SerialConfig);
  645.     ResetModem(Config -> ModemConfig);
  646.     ResetScreen(Config -> ScreenConfig);
  647.     ResetTerminal(Config -> TerminalConfig);
  648.     ResetEmulation(Config -> EmulationConfig);
  649.     ResetClip(Config -> ClipConfig);
  650.     ResetCapture(Config -> CaptureConfig);
  651.     ResetMisc(Config -> MiscConfig);
  652.     ResetCommand(Config -> CommandConfig);
  653.     ResetTransfer(Config -> TransferConfig,Config -> FileConfig -> ProtocolFileName);
  654. }
  655.  
  656. VOID __regargs
  657. DeleteConfigEntry(struct Configuration *Config,BYTE Type)
  658. {
  659.     if(Type == PREF_ALL)
  660.     {
  661.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  662.             DeleteConfigEntry(Config,Type);
  663.     }
  664.     else
  665.     {
  666.         switch(Type)
  667.         {
  668.             case PREF_SERIAL:
  669.  
  670.                 if(Config -> SerialConfig)
  671.                 {
  672.                     FreeVecPooled(Config -> SerialConfig);
  673.  
  674.                     Config -> SerialConfig = NULL;
  675.                 }
  676.  
  677.                 break;
  678.  
  679.             case PREF_MODEM:
  680.  
  681.                 if(Config -> ModemConfig)
  682.                 {
  683.                     FreeVecPooled(Config -> ModemConfig);
  684.  
  685.                     Config -> ModemConfig = NULL;
  686.                 }
  687.  
  688.                 break;
  689.  
  690.             case PREF_COMMAND:
  691.  
  692.                 if(Config -> CommandConfig)
  693.                 {
  694.                     FreeVecPooled(Config -> CommandConfig);
  695.  
  696.                     Config -> CommandConfig = NULL;
  697.                 }
  698.  
  699.                 break;
  700.  
  701.             case PREF_SCREEN:
  702.  
  703.                 if(Config -> ScreenConfig)
  704.                 {
  705.                     FreeVecPooled(Config -> ScreenConfig);
  706.  
  707.                     Config -> ScreenConfig = NULL;
  708.                 }
  709.  
  710.                 break;
  711.  
  712.             case PREF_TERMINAL:
  713.  
  714.                 if(Config -> TerminalConfig)
  715.                 {
  716.                     FreeVecPooled(Config -> TerminalConfig);
  717.  
  718.                     Config -> TerminalConfig = NULL;
  719.                 }
  720.  
  721.                 break;
  722.  
  723.             case PREF_PATH:
  724.  
  725.                 if(Config -> PathConfig)
  726.                 {
  727.                     FreeVecPooled(Config -> PathConfig);
  728.  
  729.                     Config -> PathConfig = NULL;
  730.                 }
  731.  
  732.                 break;
  733.  
  734.             case PREF_MISC:
  735.  
  736.                 if(Config -> MiscConfig)
  737.                 {
  738.                     FreeVecPooled(Config -> MiscConfig);
  739.  
  740.                     Config -> MiscConfig = NULL;
  741.                 }
  742.  
  743.                 break;
  744.  
  745.             case PREF_CLIP:
  746.  
  747.                 if(Config -> ClipConfig)
  748.                 {
  749.                     FreeVecPooled(Config -> ClipConfig);
  750.  
  751.                     Config -> ClipConfig = NULL;
  752.                 }
  753.  
  754.                 break;
  755.  
  756.             case PREF_CAPTURE:
  757.  
  758.                 if(Config -> CaptureConfig)
  759.                 {
  760.                     FreeVecPooled(Config -> CaptureConfig);
  761.  
  762.                     Config -> CaptureConfig = NULL;
  763.                 }
  764.  
  765.                 break;
  766.  
  767.             case PREF_FILE:
  768.  
  769.                 if(Config -> FileConfig)
  770.                 {
  771.                     FreeVecPooled(Config -> FileConfig);
  772.  
  773.                     Config -> FileConfig = NULL;
  774.                 }
  775.  
  776.                 break;
  777.  
  778.             case PREF_EMULATION:
  779.  
  780.                 if(Config -> EmulationConfig)
  781.                 {
  782.                     FreeVecPooled(Config -> EmulationConfig);
  783.  
  784.                     Config -> EmulationConfig = NULL;
  785.                 }
  786.  
  787.                 break;
  788.  
  789.             case PREF_TRANSFER:
  790.  
  791.                 if(Config -> TransferConfig)
  792.                 {
  793.                     FreeVecPooled(Config -> TransferConfig);
  794.  
  795.                     Config -> TransferConfig = NULL;
  796.                 }
  797.  
  798.                 break;
  799.         }
  800.     }
  801. }
  802.  
  803. VOID __regargs
  804. ResetConfigEntry(struct Configuration *Configuration,BYTE Type,BYTE Default)
  805. {
  806.     if(Type == PREF_ALL)
  807.     {
  808.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  809.             ResetConfigEntry(Configuration,Type,Default);
  810.     }
  811.     else
  812.     {
  813.         switch(Type)
  814.         {
  815.             case PREF_SERIAL:
  816.  
  817.                 if(Default || !Config -> SerialConfig)
  818.                     ResetSerialConfig(Configuration -> SerialConfig);
  819.                 else
  820.                     memcpy(Configuration -> SerialConfig,Config -> SerialConfig,sizeof(struct SerialSettings));
  821.  
  822.                 break;
  823.  
  824.             case PREF_MODEM:
  825.  
  826.                 if(Default || !Config -> ModemConfig)
  827.                     ResetModem(Configuration -> ModemConfig);
  828.                 else
  829.                     memcpy(Configuration -> ModemConfig,Config -> ModemConfig,sizeof(struct ModemSettings));
  830.  
  831.                 break;
  832.  
  833.             case PREF_COMMAND:
  834.  
  835.                 if(Default || !Config -> CommandConfig)
  836.                     ResetCommand(Configuration -> CommandConfig);
  837.                 else
  838.                     memcpy(Configuration -> CommandConfig,Config -> CommandConfig,sizeof(struct CommandSettings));
  839.  
  840.                 break;
  841.  
  842.             case PREF_SCREEN:
  843.  
  844.                 if(Default || !Config -> ScreenConfig)
  845.                     ResetScreen(Configuration -> ScreenConfig);
  846.                 else
  847.                     memcpy(Configuration -> ScreenConfig,Config -> ScreenConfig,sizeof(struct ScreenSettings));
  848.  
  849.                 FixScreenPens(Configuration -> ScreenConfig);
  850.  
  851.                 break;
  852.  
  853.             case PREF_TERMINAL:
  854.  
  855.                 if(Default || !Config -> TerminalConfig)
  856.                     ResetTerminal(Configuration -> TerminalConfig);
  857.                 else
  858.                     memcpy(Configuration -> TerminalConfig,Config -> TerminalConfig,sizeof(struct TerminalSettings));
  859.  
  860.                 break;
  861.  
  862.             case PREF_PATH:
  863.  
  864.                 if(Default || !Config -> PathConfig)
  865.                     ResetPath(Configuration -> PathConfig,NULL);
  866.                 else
  867.                     memcpy(Configuration -> PathConfig,Config -> PathConfig,sizeof(struct PathSettings));
  868.  
  869.                 break;
  870.  
  871.             case PREF_MISC:
  872.  
  873.                 if(Default || !Config -> MiscConfig)
  874.                     ResetMisc(Configuration -> MiscConfig);
  875.                 else
  876.                     memcpy(Configuration -> MiscConfig,Config -> MiscConfig,sizeof(struct MiscSettings));
  877.  
  878.                 break;
  879.  
  880.             case PREF_CLIP:
  881.  
  882.                 if(Default || !Config -> ClipConfig)
  883.                     ResetClip(Configuration -> ClipConfig);
  884.                 else
  885.                     memcpy(Configuration -> ClipConfig,Config -> ClipConfig,sizeof(struct ClipSettings));
  886.  
  887.                 break;
  888.  
  889.             case PREF_CAPTURE:
  890.  
  891.                 if(Default || !Config -> CaptureConfig)
  892.                     ResetCapture(Configuration -> CaptureConfig);
  893.                 else
  894.                     memcpy(Configuration -> CaptureConfig,Config -> CaptureConfig,sizeof(struct CaptureSettings));
  895.  
  896.                 break;
  897.  
  898.             case PREF_FILE:
  899.  
  900.                 if(Default || !Config -> FileConfig)
  901.                     ResetFile(Configuration -> FileConfig,NULL);
  902.                 else
  903.                     memcpy(Configuration -> FileConfig,Config -> FileConfig,sizeof(struct FileSettings));
  904.  
  905.                 break;
  906.  
  907.             case PREF_EMULATION:
  908.  
  909.                 if(Default || !Config -> EmulationConfig)
  910.                     ResetEmulation(Configuration -> EmulationConfig);
  911.                 else
  912.                     memcpy(Configuration -> EmulationConfig,Config -> EmulationConfig,sizeof(struct EmulationSettings));
  913.  
  914.                 break;
  915.  
  916.             case PREF_TRANSFER:
  917.  
  918.                 if(Default || !Config -> TransferConfig)
  919.                     ResetTransfer(Configuration -> TransferConfig,Config -> FileConfig -> ProtocolFileName);
  920.                 else
  921.                     memcpy(Configuration -> TransferConfig,Config -> TransferConfig,sizeof(struct TransferSettings));
  922.  
  923.                 break;
  924.         }
  925.     }
  926. }
  927.  
  928. APTR __regargs
  929. GetConfigEntry(struct Configuration *Config,BYTE Type)
  930. {
  931.     switch(Type)
  932.     {
  933.         case PREF_SERIAL:
  934.  
  935.             return(Config -> SerialConfig);
  936.  
  937.         case PREF_MODEM:
  938.  
  939.             return(Config -> ModemConfig);
  940.  
  941.         case PREF_COMMAND:
  942.  
  943.             return(Config -> CommandConfig);
  944.  
  945.         case PREF_SCREEN:
  946.  
  947.             return(Config -> ScreenConfig);
  948.  
  949.         case PREF_TERMINAL:
  950.  
  951.             return(Config -> TerminalConfig);
  952.  
  953.         case PREF_PATH:
  954.  
  955.             return(Config -> PathConfig);
  956.  
  957.         case PREF_MISC:
  958.  
  959.             return(Config -> MiscConfig);
  960.  
  961.         case PREF_CLIP:
  962.  
  963.             return(Config -> ClipConfig);
  964.  
  965.         case PREF_CAPTURE:
  966.  
  967.             return(Config -> CaptureConfig);
  968.  
  969.         case PREF_FILE:
  970.  
  971.             return(Config -> FileConfig);
  972.  
  973.         case PREF_EMULATION:
  974.  
  975.             return(Config -> EmulationConfig);
  976.  
  977.         case PREF_TRANSFER:
  978.  
  979.             return(Config -> TransferConfig);
  980.  
  981.         default:
  982.  
  983.             return(NULL);
  984.     }
  985. }
  986.  
  987. BYTE __regargs
  988. CreateConfigEntry(struct Configuration *Config,BYTE Type)
  989. {
  990.     if(Type == PREF_ALL)
  991.     {
  992.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  993.         {
  994.             if(!CreateConfigEntry(Config,Type))
  995.             {
  996.                 DeleteConfigEntry(Config,PREF_ALL);
  997.  
  998.                 return(FALSE);
  999.             }
  1000.         }
  1001.  
  1002.         return(TRUE);
  1003.     }
  1004.     else
  1005.     {
  1006.         APTR Data;
  1007.  
  1008.         switch(Type)
  1009.         {
  1010.             case PREF_SERIAL:
  1011.  
  1012.                 Data = Config -> SerialConfig;
  1013.                 break;
  1014.  
  1015.             case PREF_MODEM:
  1016.  
  1017.                 Data = Config -> ModemConfig;
  1018.                 break;
  1019.  
  1020.             case PREF_COMMAND:
  1021.  
  1022.                 Data = Config -> CommandConfig;
  1023.                 break;
  1024.  
  1025.             case PREF_SCREEN:
  1026.  
  1027.                 Data = Config -> ScreenConfig;
  1028.                 break;
  1029.  
  1030.             case PREF_TERMINAL:
  1031.  
  1032.                 Data = Config -> TerminalConfig;
  1033.                 break;
  1034.  
  1035.             case PREF_PATH:
  1036.  
  1037.                 Data = Config -> PathConfig;
  1038.                 break;
  1039.  
  1040.             case PREF_MISC:
  1041.  
  1042.                 Data = Config -> MiscConfig;
  1043.                 break;
  1044.  
  1045.             case PREF_CLIP:
  1046.  
  1047.                 Data = Config -> ClipConfig;
  1048.                 break;
  1049.  
  1050.             case PREF_CAPTURE:
  1051.  
  1052.                 Data = Config -> CaptureConfig;
  1053.                 break;
  1054.  
  1055.             case PREF_FILE:
  1056.  
  1057.                 Data = Config -> FileConfig;
  1058.                 break;
  1059.  
  1060.             case PREF_EMULATION:
  1061.  
  1062.                 Data = Config -> EmulationConfig;
  1063.                 break;
  1064.  
  1065.             case PREF_TRANSFER:
  1066.  
  1067.                 Data = Config -> TransferConfig;
  1068.                 break;
  1069.  
  1070.             default:
  1071.  
  1072.                 return(FALSE);
  1073.         }
  1074.  
  1075.         if(!Data)
  1076.         {
  1077.             if(Data = AllocVecPooled(SizeTable[Type - 1],MEMF_ANY | MEMF_CLEAR))
  1078.             {
  1079.                 (*ResetTable[Type - 1])(Data,NULL);
  1080.  
  1081.                 switch(Type)
  1082.                 {
  1083.                     case PREF_SERIAL:
  1084.  
  1085.                         Config -> SerialConfig        = Data;
  1086.                         break;
  1087.  
  1088.                     case PREF_MODEM:
  1089.  
  1090.                         Config -> ModemConfig        = Data;
  1091.                         break;
  1092.  
  1093.                     case PREF_COMMAND:
  1094.  
  1095.                         Config -> CommandConfig        = Data;
  1096.                         break;
  1097.  
  1098.                     case PREF_SCREEN:
  1099.  
  1100.                         Config -> ScreenConfig        = Data;
  1101.                         break;
  1102.  
  1103.                     case PREF_TERMINAL:
  1104.  
  1105.                         Config -> TerminalConfig    = Data;
  1106.                         break;
  1107.  
  1108.                     case PREF_PATH:
  1109.  
  1110.                         Config -> PathConfig        = Data;
  1111.                         break;
  1112.  
  1113.                     case PREF_MISC:
  1114.  
  1115.                         Config -> MiscConfig        = Data;
  1116.                         break;
  1117.  
  1118.                     case PREF_CLIP:
  1119.  
  1120.                         Config -> ClipConfig        = Data;
  1121.                         break;
  1122.  
  1123.                     case PREF_CAPTURE:
  1124.  
  1125.                         Config -> CaptureConfig        = Data;
  1126.                         break;
  1127.  
  1128.                     case PREF_FILE:
  1129.  
  1130.                         Config -> FileConfig        = Data;
  1131.                         break;
  1132.  
  1133.                     case PREF_EMULATION:
  1134.  
  1135.                         Config -> EmulationConfig    = Data;
  1136.                         break;
  1137.  
  1138.                     case PREF_TRANSFER:
  1139.  
  1140.                         Config -> TransferConfig    = Data;
  1141.                         break;
  1142.                 }
  1143.  
  1144.                 return(TRUE);
  1145.             }
  1146.             else
  1147.                 return(FALSE);
  1148.         }
  1149.         else
  1150.             return(TRUE);
  1151.     }
  1152. }
  1153.  
  1154. VOID __regargs
  1155. DeleteConfiguration(struct Configuration *Config)
  1156. {
  1157.     if(Config)
  1158.     {
  1159.         DeleteConfigEntry(Config,PREF_ALL);
  1160.  
  1161.         FreeVecPooled(Config);
  1162.     }
  1163. }
  1164.  
  1165. struct Configuration * __regargs
  1166. CreateConfiguration(BYTE Fill)
  1167. {
  1168.     struct Configuration *Config;
  1169.  
  1170.     if(Config = (struct Configuration *)AllocVecPooled(sizeof(struct Configuration),MEMF_ANY | MEMF_CLEAR))
  1171.     {
  1172.         if(Fill)
  1173.         {
  1174.             if(!CreateConfigEntry(Config,PREF_ALL))
  1175.             {
  1176.                 FreeVecPooled(Config);
  1177.  
  1178.                 return(NULL);
  1179.             }
  1180.         }
  1181.  
  1182.         return(Config);
  1183.     }
  1184.     else
  1185.         return(NULL);
  1186. }
  1187.  
  1188. STATIC BYTE
  1189. WriteConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,BYTE Type,APTR TempBuffer,STRPTR Password)
  1190. {
  1191.     APTR Data;
  1192.  
  1193.     switch(Type)
  1194.     {
  1195.         case PREF_SERIAL:
  1196.  
  1197.             Data = Config -> SerialConfig;
  1198.             break;
  1199.  
  1200.         case PREF_MODEM:
  1201.  
  1202.             Data = Config -> ModemConfig;
  1203.             break;
  1204.  
  1205.         case PREF_COMMAND:
  1206.  
  1207.             Data = Config -> CommandConfig;
  1208.             break;
  1209.  
  1210.         case PREF_SCREEN:
  1211.  
  1212.             Data = Config -> ScreenConfig;
  1213.             break;
  1214.  
  1215.         case PREF_TERMINAL:
  1216.  
  1217.             Data = Config -> TerminalConfig;
  1218.             break;
  1219.  
  1220.         case PREF_PATH:
  1221.  
  1222.             Data = Config -> PathConfig;
  1223.             break;
  1224.  
  1225.         case PREF_MISC:
  1226.  
  1227.             Data = Config -> MiscConfig;
  1228.             break;
  1229.  
  1230.         case PREF_CLIP:
  1231.  
  1232.             Data = Config -> ClipConfig;
  1233.             break;
  1234.  
  1235.         case PREF_CAPTURE:
  1236.  
  1237.             Data = Config -> CaptureConfig;
  1238.             break;
  1239.  
  1240.         case PREF_FILE:
  1241.  
  1242.             Data = Config -> FileConfig;
  1243.             break;
  1244.  
  1245.         case PREF_EMULATION:
  1246.  
  1247.             Data = Config -> EmulationConfig;
  1248.             break;
  1249.  
  1250.         case PREF_TRANSFER:
  1251.  
  1252.             Data = Config -> TransferConfig;
  1253.             break;
  1254.  
  1255.         default:
  1256.  
  1257.             Data = NULL;
  1258.             break;
  1259.     }
  1260.  
  1261.     if(Data)
  1262.     {
  1263.         if(TempBuffer)
  1264.         {
  1265.             Encrypt(Data,SizeTable[Type - 1],TempBuffer,Password,20);
  1266.  
  1267.             Data = TempBuffer;
  1268.         }
  1269.  
  1270.         if(!PushChunk(Handle,0,TypeTable[Type - 1],SizeTable[Type - 1]))
  1271.         {
  1272.             if(WriteChunkRecords(Handle,Data,SizeTable[Type - 1],1) == 1)
  1273.             {
  1274.                 if(!PopChunk(Handle))
  1275.                     return(TRUE);
  1276.             }
  1277.         }
  1278.  
  1279.         return(FALSE);
  1280.     }
  1281.     else
  1282.         return(TRUE);
  1283. }
  1284.  
  1285. STATIC UBYTE
  1286. IsConfigChunk(ULONG ID)
  1287. {
  1288.     UBYTE Type;
  1289.  
  1290.     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1291.     {
  1292.         if(ID == TypeTable[Type - 1])
  1293.             return(Type);
  1294.     }
  1295.  
  1296.     return(0);
  1297. }
  1298.  
  1299. STATIC BYTE
  1300. WriteConfigChunks(struct IFFHandle *Handle,struct Configuration *Config,APTR TempBuffer,STRPTR Password)
  1301. {
  1302.     UBYTE Type;
  1303.  
  1304.     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1305.     {
  1306.         if(!WriteConfigChunk(Handle,Config,Type,TempBuffer,Password))
  1307.             return(FALSE);
  1308.     }
  1309.  
  1310.     return(TRUE);
  1311. }
  1312.  
  1313. VOID __regargs
  1314. SaveConfig(struct Configuration *Src,struct Configuration *Dst)
  1315. {
  1316.     if(Dst -> SerialConfig && Src -> SerialConfig)
  1317.         memcpy(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1318.  
  1319.     if(Dst -> ModemConfig && Src -> ModemConfig)
  1320.         memcpy(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1321.  
  1322.     if(Dst -> ScreenConfig && Src -> ScreenConfig)
  1323.     {
  1324.         memcpy(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1325.  
  1326.         FixScreenPens(Dst -> ScreenConfig);
  1327.     }
  1328.  
  1329.     if(Dst -> TerminalConfig && Src -> TerminalConfig)
  1330.         memcpy(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1331.  
  1332.     if(Dst -> EmulationConfig && Src -> EmulationConfig)
  1333.         memcpy(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1334.  
  1335.     if(Dst -> ClipConfig && Src -> ClipConfig)
  1336.         memcpy(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1337.  
  1338.     if(Dst -> CaptureConfig && Src -> CaptureConfig)
  1339.         memcpy(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1340.  
  1341.     if(Dst -> CommandConfig && Src -> CommandConfig)
  1342.         memcpy(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1343.  
  1344.     if(Dst -> MiscConfig && Src -> MiscConfig)
  1345.         memcpy(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1346.  
  1347.     if(Dst -> PathConfig && Src -> PathConfig)
  1348.         memcpy(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1349.  
  1350.     if(Dst -> FileConfig && Src -> FileConfig)
  1351.         memcpy(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1352.  
  1353.     if(Dst -> TransferConfig && Src -> TransferConfig)
  1354.         memcpy(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1355. }
  1356.  
  1357. VOID __regargs
  1358. UpdateConfig(struct Configuration *Src,struct Configuration *Dst)
  1359. {
  1360.     if(Src -> SerialConfig)
  1361.         memcpy(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1362.  
  1363.     if(Src -> ModemConfig)
  1364.         memcpy(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1365.  
  1366.     if(Src -> ScreenConfig)
  1367.     {
  1368.         memcpy(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1369.  
  1370.         FixScreenPens(Dst -> ScreenConfig);
  1371.     }
  1372.  
  1373.     if(Src -> TerminalConfig)
  1374.         memcpy(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1375.  
  1376.     if(Src -> EmulationConfig)
  1377.         memcpy(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1378.  
  1379.     if(Src -> ClipConfig)
  1380.         memcpy(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1381.  
  1382.     if(Src -> CaptureConfig)
  1383.         memcpy(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1384.  
  1385.     if(Src -> CommandConfig)
  1386.         memcpy(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1387.  
  1388.     if(Src -> MiscConfig)
  1389.         memcpy(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1390.  
  1391.     if(Src -> PathConfig)
  1392.         memcpy(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1393.  
  1394.     if(Src -> FileConfig)
  1395.         memcpy(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1396.  
  1397.     if(Src -> TransferConfig)
  1398.         memcpy(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1399. }
  1400.  
  1401. VOID __regargs
  1402. SwapConfig(struct Configuration *Src,struct Configuration *Dst)
  1403. {
  1404.     swmem(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1405.     swmem(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1406.     swmem(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1407.     swmem(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1408.     swmem(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1409.     swmem(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1410.     swmem(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1411.     swmem(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1412.     swmem(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1413.     swmem(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1414.     swmem(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1415.     swmem(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1416. }
  1417.  
  1418.     /* SavePhonebook(STRPTR Name):
  1419.      *
  1420.      *    Save the current phone book to a disk file.
  1421.      */
  1422.  
  1423. BYTE __regargs
  1424. SavePhonebook(STRPTR Name)
  1425. {
  1426.     struct IFFHandle    *Handle;
  1427.     BYTE             Success = FALSE;
  1428.     LONG             Error = 0;
  1429.  
  1430.     if(Phonebook && NumPhoneEntries)
  1431.     {
  1432.         if(Handle = (struct IFFHandle *)AllocIFF())
  1433.         {
  1434.             if(Handle -> iff_Stream = Open(Name,MODE_NEWFILE))
  1435.             {
  1436.                 InitIFFasDOS(Handle);
  1437.  
  1438.                 if(!(Error = OpenIFF(Handle,IFFF_WRITE)))
  1439.                 {
  1440.                     if(!(Error = PushChunk(Handle,ID_TERM,ID_CAT,IFFSIZE_UNKNOWN)))
  1441.                     {
  1442.                         if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  1443.                         {
  1444.                             if(!(Error = PushChunk(Handle,0,ID_VERS,IFFSIZE_UNKNOWN)))
  1445.                             {
  1446.                                 struct TermInfo TermInfo;
  1447.  
  1448.                                 TermInfo . Version    = TermVersion;
  1449.                                 TermInfo . Revision    = TermRevision;
  1450.  
  1451.                                 if(WriteChunkRecords(Handle,&TermInfo,sizeof(struct TermInfo),1) == 1)
  1452.                                 {
  1453.                                     if(!(Error = PopChunk(Handle)))
  1454.                                     {
  1455.                                         STRPTR TempBuffer = NULL;
  1456.  
  1457.                                         if(PhonePasswordUsed)
  1458.                                         {
  1459.                                             if(!(Error = PushChunk(Handle,0,ID_PSWD,20)))
  1460.                                             {
  1461.                                                 Success = TRUE;
  1462.  
  1463.                                                 if(WriteChunkBytes(Handle,PhonePassword,20) != 20)
  1464.                                                     Success = FALSE;
  1465.  
  1466.                                                 if(PopChunk(Handle))
  1467.                                                     Success = FALSE;
  1468.  
  1469.                                                 if(Success)
  1470.                                                 {
  1471.                                                     LONG Max = sizeof(struct PhoneHeader),Type;
  1472.  
  1473.                                                     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1474.                                                     {
  1475.                                                         if(SizeTable[Type - 1] > Max)
  1476.                                                             Max = SizeTable[Type - 1];
  1477.                                                     }
  1478.  
  1479.                                                     if(!(TempBuffer = AllocVecPooled(Max,MEMF_ANY)))
  1480.                                                     {
  1481.                                                         Error = ERR_NO_MEM;
  1482.  
  1483.                                                         Success = FALSE;
  1484.                                                     }
  1485.                                                 }
  1486.                                             }
  1487.                                         }
  1488.                                         else
  1489.                                             Success = TRUE;
  1490.  
  1491.                                         if(Success)
  1492.                                         {
  1493.                                             Success = FALSE;
  1494.  
  1495.                                             if(!(Error = PushChunk(Handle,0,ID_DIAL,IFFSIZE_UNKNOWN)))
  1496.                                             {
  1497.                                                 if(WriteChunkBytes(Handle,&NumPhoneEntries,sizeof(LONG)) == sizeof(LONG))
  1498.                                                 {
  1499.                                                     if(!(Error = PopChunk(Handle)))
  1500.                                                     {
  1501.                                                         if(!(Error = PopChunk(Handle)))
  1502.                                                         {
  1503.                                                             LONG i;
  1504.  
  1505.                                                             Success = TRUE;
  1506.  
  1507.                                                             for(i = 0 ; Success && i < NumPhoneEntries ; i++)
  1508.                                                             {
  1509.                                                                 Success = FALSE;
  1510.  
  1511.                                                                 if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  1512.                                                                 {
  1513.                                                                     if(!(Error = PushChunk(Handle,0,ID_PHON,sizeof(struct PhoneHeader))))
  1514.                                                                     {
  1515.                                                                         if(TempBuffer)
  1516.                                                                         {
  1517.                                                                             Encrypt((UBYTE *)Phonebook[i] -> Header,sizeof(struct PhoneHeader),TempBuffer,PhonePassword,20);
  1518.  
  1519.                                                                             if(WriteChunkRecords(Handle,TempBuffer,sizeof(struct PhoneHeader),1) == 1)
  1520.                                                                             {
  1521.                                                                                 if(!(Error = PopChunk(Handle)))
  1522.                                                                                 {
  1523.                                                                                     if(WriteConfigChunks(Handle,Phonebook[i] -> Config,TempBuffer,PhonePassword))
  1524.                                                                                     {
  1525.                                                                                         struct TimeDateNode *TimeDateNode;
  1526.  
  1527.                                                                                         Success = TRUE;
  1528.  
  1529.                                                                                         TimeDateNode = (struct TimeDateNode *)Phonebook[i] -> TimeDateList . mlh_Head;
  1530.  
  1531.                                                                                         while(TimeDateNode -> VanillaNode . ln_Succ)
  1532.                                                                                         {
  1533.                                                                                             if(!(Error = PushChunk(Handle,0,ID_DATE,IFFSIZE_UNKNOWN)))
  1534.                                                                                             {
  1535.                                                                                                 if(WriteChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) != sizeof(struct TimeDateHeader))
  1536.                                                                                                 {
  1537.                                                                                                     Error = IoErr();
  1538.  
  1539.                                                                                                     Success = FALSE;
  1540.  
  1541.                                                                                                     break;
  1542.                                                                                                 }
  1543.                                                                                                 else
  1544.                                                                                                 {
  1545.                                                                                                     if(WriteChunkBytes(Handle,TimeDateNode -> Table,TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate)) != TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate))
  1546.                                                                                                     {
  1547.                                                                                                         Error = IoErr();
  1548.  
  1549.                                                                                                         Success = FALSE;
  1550.  
  1551.                                                                                                         break;
  1552.                                                                                                     }
  1553.                                                                                                 }
  1554.  
  1555.                                                                                                 if(Success)
  1556.                                                                                                 {
  1557.                                                                                                     if(Error = PopChunk(Handle))
  1558.                                                                                                     {
  1559.                                                                                                         Success = FALSE;
  1560.     
  1561.                                                                                                         break;
  1562.                                                                                                     }
  1563.                                                                                                 }
  1564.  
  1565.                                                                                                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  1566.                                                                                             }
  1567.                                                                                         }
  1568.                                                                                     }
  1569.                                                                                     else
  1570.                                                                                     {
  1571.                                                                                         Error = IoErr();
  1572.  
  1573.                                                                                         Success = FALSE;
  1574.                                                                                     }
  1575.                                                                                 }
  1576.                                                                             }
  1577.                                                                             else
  1578.                                                                                 Error = IoErr();
  1579.                                                                         }
  1580.                                                                         else
  1581.                                                                         {
  1582.                                                                             if(WriteChunkRecords(Handle,Phonebook[i] -> Header,sizeof(struct PhoneHeader),1) == 1)
  1583.                                                                             {
  1584.                                                                                 if(!(Error = PopChunk(Handle)))
  1585.                                                                                 {
  1586.                                                                                     if(WriteConfigChunks(Handle,Phonebook[i] -> Config,NULL,NULL))
  1587.                                                                                     {
  1588.                                                                                         struct TimeDateNode *TimeDateNode;
  1589.  
  1590.                                                                                         Success = TRUE;
  1591.  
  1592.                                                                                         TimeDateNode = (struct TimeDateNode *)Phonebook[i] -> TimeDateList . mlh_Head;
  1593.  
  1594.                                                                                         while(TimeDateNode -> VanillaNode . ln_Succ)
  1595.                                                                                         {
  1596.                                                                                             if(!(Error = PushChunk(Handle,0,ID_DATE,IFFSIZE_UNKNOWN)))
  1597.                                                                                             {
  1598.                                                                                                 if(WriteChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) != sizeof(struct TimeDateHeader))
  1599.                                                                                                 {
  1600.                                                                                                     Error = IoErr();
  1601.  
  1602.                                                                                                     Success = FALSE;
  1603.  
  1604.                                                                                                     break;
  1605.                                                                                                 }
  1606.                                                                                                 else
  1607.                                                                                                 {
  1608.                                                                                                     if(WriteChunkBytes(Handle,TimeDateNode -> Table,TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate)) != TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate))
  1609.                                                                                                     {
  1610.                                                                                                         Error = IoErr();
  1611.  
  1612.                                                                                                         Success = FALSE;
  1613.  
  1614.                                                                                                         break;
  1615.                                                                                                     }
  1616.                                                                                                 }
  1617.  
  1618.                                                                                                 if(Success)
  1619.                                                                                                 {
  1620.                                                                                                     if(Error = PopChunk(Handle))
  1621.                                                                                                     {
  1622.                                                                                                         Success = FALSE;
  1623.     
  1624.                                                                                                         break;
  1625.                                                                                                     }
  1626.                                                                                                 }
  1627.  
  1628.                                                                                                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  1629.                                                                                             }
  1630.                                                                                         }
  1631.                                                                                     }
  1632.                                                                                     else
  1633.                                                                                     {
  1634.                                                                                         Success = FALSE;
  1635.  
  1636.                                                                                         Error = IoErr();
  1637.                                                                                     }
  1638.                                                                                 }
  1639.                                                                             }
  1640.                                                                             else
  1641.                                                                                 Error = IoErr();
  1642.                                                                         }
  1643.                                                                     }
  1644.  
  1645.                                                                     if(Success)
  1646.                                                                     {
  1647.                                                                         if(PopChunk(Handle))
  1648.                                                                             Success = FALSE;
  1649.                                                                     }
  1650.                                                                 }
  1651.                                                             }
  1652.                                                         }
  1653.                                                     }
  1654.                                                 }
  1655.                                                 else
  1656.                                                     Error = IoErr();
  1657.                                             }
  1658.                                         }
  1659.  
  1660.                                         if(TempBuffer)
  1661.                                             FreeVecPooled(TempBuffer);
  1662.                                     }
  1663.                                 }
  1664.                                 else
  1665.                                     Error = IoErr();
  1666.                             }
  1667.                         }
  1668.  
  1669.                         if(Success)
  1670.                         {
  1671.                             if(Error = PopChunk(Handle))
  1672.                                 Success = FALSE;
  1673.                         }
  1674.                     }
  1675.  
  1676.                     CloseIFF(Handle);
  1677.                 }
  1678.  
  1679.                 Close(Handle -> iff_Stream);
  1680.             }
  1681.             else
  1682.                 Error = IoErr();
  1683.  
  1684.             FreeIFF(Handle);
  1685.         }
  1686.         else
  1687.             Error = ERR_NO_MEM;
  1688.  
  1689.         if(Success)
  1690.             AddProtection(Name,FIBF_EXECUTE);
  1691.         else
  1692.             DeleteFile(Name);
  1693.     }
  1694.  
  1695.     if(Error)
  1696.         SetIoErr(Error);
  1697.  
  1698.     return(Success);
  1699. }
  1700.  
  1701. STATIC BYTE
  1702. ReadConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,UBYTE Type,LONG Len,STRPTR Password)
  1703. {
  1704.     if(CreateConfigEntry(Config,Type))
  1705.     {
  1706.         APTR Data;
  1707.  
  1708.         switch(Type)
  1709.         {
  1710.             case PREF_SERIAL:
  1711.  
  1712.                 Data = Config -> SerialConfig;
  1713.                 break;
  1714.  
  1715.             case PREF_MODEM:
  1716.  
  1717.                 Data = Config -> ModemConfig;
  1718.                 break;
  1719.  
  1720.             case PREF_COMMAND:
  1721.  
  1722.                 Data = Config -> CommandConfig;
  1723.                 break;
  1724.  
  1725.             case PREF_SCREEN:
  1726.  
  1727.                 Data = Config -> ScreenConfig;
  1728.                 break;
  1729.  
  1730.             case PREF_TERMINAL:
  1731.  
  1732.                 Data = Config -> TerminalConfig;
  1733.                 break;
  1734.  
  1735.             case PREF_PATH:
  1736.  
  1737.                 Data = Config -> PathConfig;
  1738.                 break;
  1739.  
  1740.             case PREF_MISC:
  1741.  
  1742.                 Data = Config -> MiscConfig;
  1743.                 break;
  1744.  
  1745.             case PREF_CLIP:
  1746.  
  1747.                 Data = Config -> ClipConfig;
  1748.                 break;
  1749.  
  1750.             case PREF_CAPTURE:
  1751.  
  1752.                 Data = Config -> CaptureConfig;
  1753.                 break;
  1754.  
  1755.             case PREF_FILE:
  1756.  
  1757.                 Data = Config -> FileConfig;
  1758.                 break;
  1759.  
  1760.             case PREF_EMULATION:
  1761.  
  1762.                 Data = Config -> EmulationConfig;
  1763.                 break;
  1764.  
  1765.             case PREF_TRANSFER:
  1766.  
  1767.                 Data = Config -> TransferConfig;
  1768.                 break;
  1769.         }
  1770.  
  1771.         Len = MIN(SizeTable[Type - 1],Len);
  1772.  
  1773.         if(ReadChunkBytes(Handle,Data,Len) == Len)
  1774.         {
  1775.             if(Password)
  1776.                 Decrypt(Data,Len,Data,Password,20);
  1777.  
  1778.             if(Type == PREF_SCREEN)
  1779.                 FixScreenPens(Data);
  1780.  
  1781.             return(TRUE);
  1782.         }
  1783.     }
  1784.  
  1785.     return(FALSE);
  1786. }
  1787.  
  1788.     /* LoadPhonebook(STRPTR Name):
  1789.      *
  1790.      *    Restore a phone book from a disk file.
  1791.      */
  1792.  
  1793. BYTE __regargs
  1794. LoadPhonebook(STRPTR Name)
  1795. {
  1796.     struct PhoneEntry    **PrivatePhonebook;
  1797.     LONG             PrivatePhoneSize    = 0,
  1798.                  CurrentPhoneSize    = 0,
  1799.                  Count            = 0,
  1800.                  Index            = 0;
  1801.     BYTE             Success        = FALSE,
  1802.                  LastHadTime        = TRUE,
  1803.                  UsePhonePassword    = FALSE,
  1804.                  FirstChunk        = TRUE,
  1805.                  UseOld            = FALSE;
  1806.     struct IFFHandle    *Handle;
  1807.     struct ContextNode    *Chunk;
  1808.     struct TimeDateNode    *TimeDateNode;
  1809.     UBYTE             ConfigChunkType,
  1810.                  PasswordBuffer[20];
  1811.     BYTE             CheckedChunk = FALSE;
  1812.     LONG             Error = 0;
  1813.  
  1814.     if(Handle = AllocIFF())
  1815.     {
  1816.         if(Handle -> iff_Stream = Open(Name,MODE_OLDFILE))
  1817.         {
  1818.             InitIFFasDOS(Handle);
  1819.  
  1820.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  1821.             {
  1822.                 if(!(Error = StopChunks(Handle,(LONG *)Stops,NUM_STOPS)))
  1823.                 {
  1824.                     struct TermInfo TermInfo;
  1825.  
  1826.                     while(!ParseIFF(Handle,IFFPARSE_SCAN))
  1827.                     {
  1828.                         Chunk = CurrentChunk(Handle);
  1829.  
  1830.                             /* Is this the first chunk to be read? */
  1831.  
  1832.                         if(!CheckedChunk)
  1833.                         {
  1834.                                 /* The first chunk must be a
  1835.                                  * catalog chunk, or this is
  1836.                                  * not a proper phonebook file.
  1837.                                  */
  1838.  
  1839.                             if(Chunk -> cn_ID != ID_CAT)
  1840.                                 break;
  1841.                             else
  1842.                                 CheckedChunk = TRUE;
  1843.                         }
  1844.  
  1845.                         if(Chunk -> cn_ID == ID_VERS)
  1846.                         {
  1847.                             if(ReadChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  1848.                             {
  1849.                                 if(TermInfo . Version != TermVersion || (TermInfo . Version == TermVersion && TermInfo . Revision > TermRevision))
  1850.                                 {
  1851.                                     if(TermInfo . Version == 2 && TermInfo . Revision == 4)
  1852.                                         UseOld = TRUE;
  1853.  
  1854.                                     if(TermInfo . Version != 3)
  1855.                                         break;
  1856.                                 }
  1857.                             }
  1858.                             else
  1859.                             {
  1860.                                 Error = IoErr();
  1861.  
  1862.                                 break;
  1863.                             }
  1864.                         }
  1865.  
  1866.                         if(Chunk -> cn_ID == ID_PSWD)
  1867.                         {
  1868.                             if(ReadChunkBytes(Handle,PasswordBuffer,20) == 20)
  1869.                             {
  1870.                                 if(PhonePasswordUsed)
  1871.                                 {
  1872.                                     if(!memcmp(PhonePassword,PasswordBuffer,20))
  1873.                                     {
  1874.                                         UsePhonePassword = TRUE;
  1875.  
  1876.                                         continue;
  1877.                                     }
  1878.                                 }
  1879.  
  1880.                                 memset(SharedBuffer,0,21);
  1881.  
  1882.                                 if(GetString(FALSE,TRUE,21,LocaleString(MSG_PHONEPANEL_PLEASE_ENTER_PASSWORD_TXT),SharedBuffer))
  1883.                                 {
  1884.                                     UBYTE AnotherBuffer[20];
  1885.  
  1886.                                     Encrypt(SharedBuffer,20,AnotherBuffer,SharedBuffer,strlen(SharedBuffer));
  1887.  
  1888.                                     if(!memcmp(PasswordBuffer,AnotherBuffer,20))
  1889.                                     {
  1890.                                         UsePhonePassword = TRUE;
  1891.  
  1892.                                         continue;
  1893.                                     }
  1894.                                     else
  1895.                                     {
  1896.                                         MyEasyRequest(Window,LocaleString(MSG_TERMPHONE_WRONG_PASSWORD_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Name);
  1897.  
  1898.                                         break;
  1899.                                     }
  1900.                                 }
  1901.                                 else
  1902.                                     break;
  1903.                             }
  1904.                             else
  1905.                             {
  1906.                                 Error = IoErr();
  1907.  
  1908.                                 break;
  1909.                             }
  1910.                         }
  1911.  
  1912.                         if(Chunk -> cn_ID == ID_DIAL)
  1913.                         {
  1914.                             if(ReadChunkBytes(Handle,&CurrentPhoneSize,sizeof(LONG)) == sizeof(LONG))
  1915.                             {
  1916.                                 if(!CurrentPhoneSize)
  1917.                                     break;
  1918.                                 else
  1919.                                 {
  1920.                                     if(!(PrivatePhonebook = CreatePhonebook(CurrentPhoneSize,&PrivatePhoneSize,TRUE)))
  1921.                                     {
  1922.                                         Error = ERR_NO_MEM;
  1923.  
  1924.                                         break;
  1925.                                     }
  1926.                                 }
  1927.                             }
  1928.                             else
  1929.                             {
  1930.                                 Error = IoErr();
  1931.  
  1932.                                 break;
  1933.                             }
  1934.                         }
  1935.  
  1936.                         if(Chunk -> cn_ID == ID_PHON)
  1937.                         {
  1938.                             WORD Size = MIN(sizeof(struct PhoneHeader),Chunk -> cn_Size);
  1939.  
  1940.                             if(!CurrentPhoneSize)
  1941.                                 break;
  1942.  
  1943.                             if(!LastHadTime)
  1944.                             {
  1945.                                 if(TimeDateNode = CreateTimeDateNode(-1,-1,"",2))
  1946.                                     AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  1947.                             }
  1948.  
  1949.                             if(!FirstChunk)
  1950.                                 Index++;
  1951.                             else
  1952.                                 FirstChunk = FALSE;
  1953.  
  1954.                             if(ReadChunkBytes(Handle,PrivatePhonebook[Index] -> Header,Size) == Size)
  1955.                             {
  1956.                                 if(UsePhonePassword)
  1957.                                     Decrypt((UBYTE *)PrivatePhonebook[Index] -> Header,Size,(UBYTE *)PrivatePhonebook[Index] -> Header,PasswordBuffer,20);
  1958.  
  1959.                                 PrivatePhonebook[Index] -> Count = -1;
  1960.  
  1961.                                 LastHadTime = FALSE;
  1962.  
  1963.                                 Count++;
  1964.                             }
  1965.                             else
  1966.                             {
  1967.                                 Error = IoErr();
  1968.  
  1969.                                 break;
  1970.                             }
  1971.                         }
  1972.  
  1973.                         if(ConfigChunkType = IsConfigChunk(Chunk -> cn_ID))
  1974.                         {
  1975.                             if(!CurrentPhoneSize)
  1976.                                 break;
  1977.  
  1978.                             if(UsePhonePassword)
  1979.                             {
  1980.                                 if(!ReadConfigChunk(Handle,PrivatePhonebook[Index] -> Config,ConfigChunkType,Chunk -> cn_Size,PasswordBuffer))
  1981.                                 {
  1982.                                     if((TermInfo . Version == 3 && TermInfo . Revision < 6) || TermInfo . Version < 3)
  1983.                                         FixOldConfig(PrivatePhonebook[Index] -> Config,ConfigChunkType,TRUE);
  1984.  
  1985.                                     if(Count)
  1986.                                         CurrentPhoneSize = Count - 1;
  1987.                                     else
  1988.                                         CurrentPhoneSize = 0;
  1989.  
  1990.                                     break;
  1991.                                 }
  1992.                             }
  1993.                             else
  1994.                             {
  1995.                                 if(!ReadConfigChunk(Handle,PrivatePhonebook[Index] -> Config,ConfigChunkType,Chunk -> cn_Size,NULL))
  1996.                                 {
  1997.                                     if((TermInfo . Version == 3 && TermInfo . Revision < 6) || TermInfo . Version < 3)
  1998.                                         FixOldConfig(PrivatePhonebook[Index] -> Config,ConfigChunkType,TRUE);
  1999.  
  2000.                                     if(Count)
  2001.                                         CurrentPhoneSize = Count - 1;
  2002.                                     else
  2003.                                         CurrentPhoneSize = 0;
  2004.  
  2005.                                     break;
  2006.                                 }
  2007.                             }
  2008.                         }
  2009.  
  2010.                         if(Chunk -> cn_ID == ID_DATE)
  2011.                         {
  2012.                             WORD Count = (Chunk -> cn_Size - sizeof(struct TimeDateHeader)) / sizeof(struct TimeDate);
  2013.  
  2014.                             if(!CurrentPhoneSize)
  2015.                                 break;
  2016.  
  2017.                             if(TimeDateNode = CreateTimeDateNode(-1,-1,"",Count))
  2018.                             {
  2019.                                 if(ReadChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) == sizeof(struct TimeDateHeader))
  2020.                                 {
  2021.                                     if(ReadChunkRecords(Handle,TimeDateNode -> Table,sizeof(struct TimeDate),Count) == Count)
  2022.                                     {
  2023.                                         AdaptTimeDateNode(TimeDateNode);
  2024.  
  2025.                                         AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2026.  
  2027.                                         LastHadTime = TRUE;
  2028.                                     }
  2029.                                     else
  2030.                                     {
  2031.                                         Error = IoErr();
  2032.  
  2033.                                         FreeTimeDateNode(TimeDateNode);
  2034.                                     }
  2035.                                 }
  2036.                                 else
  2037.                                 {
  2038.                                     Error = IoErr();
  2039.  
  2040.                                     FreeTimeDateNode(TimeDateNode);
  2041.                                 }
  2042.                             }
  2043.                         }
  2044.                     }
  2045.  
  2046.                     if(CurrentPhoneSize)
  2047.                     {
  2048.                         LONG i;
  2049.  
  2050.                         if(!LastHadTime)
  2051.                         {
  2052.                             if(TimeDateNode = CreateTimeDateNode(-1,-1,"",2))
  2053.                                 AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2054.                         }
  2055.  
  2056.                         if(Phonebook)
  2057.                             DeletePhonebook(Phonebook,PhoneSize,TRUE);
  2058.  
  2059.                         Phonebook    = PrivatePhonebook;
  2060.                         PhoneSize    = PrivatePhoneSize;
  2061.                         NumPhoneEntries    = CurrentPhoneSize;
  2062.                         Success        = TRUE;
  2063.  
  2064.                         memcpy(PhonePassword,PasswordBuffer,20);
  2065.                         PhonePasswordUsed = UsePhonePassword;
  2066.  
  2067.                         for(i = NumPhoneEntries ; i < PhoneSize ; i++)
  2068.                         {
  2069.                             if(Phonebook[i])
  2070.                             {
  2071.                                 if(Phonebook[i] -> Config)
  2072.                                     DeleteConfiguration(Phonebook[i] -> Config);
  2073.  
  2074.                                 FreeVecPooled(Phonebook[i]);
  2075.  
  2076.                                 Phonebook[i] = NULL;
  2077.                             }
  2078.                         }
  2079.  
  2080.                         FreeDialList(TRUE);
  2081.                     }
  2082.                     else
  2083.                     {
  2084.                         if(PrivatePhoneSize)
  2085.                         {
  2086.                             DeletePhonebook(PrivatePhonebook,PrivatePhoneSize,TRUE);
  2087.  
  2088.                             Success = FALSE;
  2089.                         }
  2090.                     }
  2091.                 }
  2092.  
  2093.                 CloseIFF(Handle);
  2094.             }
  2095.  
  2096.             Close(Handle -> iff_Stream);
  2097.         }
  2098.         else
  2099.             Error = IoErr();
  2100.  
  2101.         FreeIFF(Handle);
  2102.     }
  2103.     else
  2104.         Error = ERR_NO_MEM;
  2105.  
  2106.     if(Error)
  2107.         SetIoErr(Error);
  2108.  
  2109.     if(UseOld)
  2110.         return(LoadOldPhonebook(Name));
  2111.     else
  2112.         return(Success);
  2113. }
  2114.  
  2115.     /* WriteConfig(STRPTR Name,struct Configuration *Config):
  2116.      *
  2117.      *    Write the configuration to a file, very much like
  2118.      *    WriteIFFData().
  2119.      */
  2120.  
  2121. BYTE __regargs
  2122. WriteConfig(STRPTR Name,struct Configuration *Config)
  2123. {
  2124.     struct IFFHandle    *Handle;
  2125.     BYTE             Success = FALSE;
  2126.     LONG             Error = 0;
  2127.  
  2128.         /* Allocate a handle. */
  2129.  
  2130.     if(Handle = AllocIFF())
  2131.     {
  2132.             /* Open an output stream. */
  2133.  
  2134.         if(Handle -> iff_Stream = Open(Name,MODE_NEWFILE))
  2135.         {
  2136.                 /* Tell iffparse that this is
  2137.                  * a DOS handle.
  2138.                  */
  2139.  
  2140.             InitIFFasDOS(Handle);
  2141.  
  2142.                 /* Open the handle for writing. */
  2143.  
  2144.             if(!(Error = OpenIFF(Handle,IFFF_WRITE)))
  2145.             {
  2146.                     /* Push outmost chunk onto stack. */
  2147.  
  2148.                 if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  2149.                 {
  2150.                         /* Add a version identifier. */
  2151.  
  2152.                     if(!(Error = PushChunk(Handle,0,ID_VERS,IFFSIZE_UNKNOWN)))
  2153.                     {
  2154.                         struct TermInfo TermInfo;
  2155.  
  2156.                         TermInfo . Version    = TermVersion;
  2157.                         TermInfo . Revision    = TermRevision;
  2158.  
  2159.                             /* Write the version data. */
  2160.  
  2161.                         if(WriteChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2162.                         {
  2163.                                 /* Pop the version chunk, i.e. write it to the file. */
  2164.  
  2165.                             if(Error = PopChunk(Handle))
  2166.                                 Success = FALSE;
  2167.                             else
  2168.                             {
  2169.                                 if(WriteConfigChunks(Handle,Config,NULL,NULL))
  2170.                                 {
  2171.                                     LONG i;
  2172.  
  2173.                                     Success = TRUE;
  2174.  
  2175.                                     for(i = 0 ; Success && i < WINDOW_COUNT ; i++)
  2176.                                     {
  2177.                                         if(!(Error = PushChunk(Handle,0,ID_WINF,sizeof(struct WindowInfo))))
  2178.                                         {
  2179.                                             if(WriteChunkBytes(Handle,&WindowInfoTable[i],sizeof(struct WindowInfo)) == sizeof(struct WindowInfo))
  2180.                                             {
  2181.                                                 if(Error = PopChunk(Handle))
  2182.                                                     Success = FALSE;
  2183.                                             }
  2184.                                             else
  2185.                                             {
  2186.                                                 Error = IoErr();
  2187.  
  2188.                                                 Success = FALSE;
  2189.                                             }
  2190.                                         }
  2191.                                         else
  2192.                                             Success = FALSE;
  2193.                                     }
  2194.                                 }
  2195.                             }
  2196.                         }
  2197.                         else
  2198.                         {
  2199.                             Error = IoErr();
  2200.  
  2201.                             Success = FALSE;
  2202.                         }
  2203.                     }
  2204.  
  2205.                         /* Seems that we're done, now try to pop the FORM chunk
  2206.                          * and return.
  2207.                          */
  2208.  
  2209.                     if(Success)
  2210.                     {
  2211.                         if(Error = PopChunk(Handle))
  2212.                             Success = FALSE;
  2213.                     }
  2214.                 }
  2215.  
  2216.                     /* Close the handle (flush any pending data). */
  2217.  
  2218.                 CloseIFF(Handle);
  2219.             }
  2220.  
  2221.                 /* Close the DOS handle itself. */
  2222.  
  2223.             Close(Handle -> iff_Stream);
  2224.         }
  2225.         else
  2226.             Error = IoErr();
  2227.  
  2228.             /* And free the IFF handle. */
  2229.  
  2230.         FreeIFF(Handle);
  2231.     }
  2232.     else
  2233.         Error = ERR_NO_MEM;
  2234.  
  2235.     if(Success)
  2236.         AddProtection(Name,FIBF_EXECUTE);
  2237.  
  2238.     return(Success);
  2239. }
  2240.  
  2241.     /* ReadConfig(STRPTR Name,struct Configuration *Config):
  2242.      *
  2243.      *    Read the configuration file, very much the same as ReadIFFData().
  2244.      */
  2245.  
  2246. BYTE __regargs
  2247. ReadConfig(STRPTR Name,struct Configuration *Config)
  2248. {
  2249.     struct IFFHandle    *Handle;
  2250.     BYTE             Success    = FALSE,
  2251.                  UseOld        = FALSE;
  2252.     struct ContextNode    *Chunk;
  2253.     UBYTE             ConfigChunkType;
  2254.     LONG             Error = 0;
  2255.  
  2256.     if(Handle = AllocIFF())
  2257.     {
  2258.         if(Handle -> iff_Stream = Open(Name,MODE_OLDFILE))
  2259.         {
  2260.             InitIFFasDOS(Handle);
  2261.  
  2262.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  2263.             {
  2264.                 if(!StopChunks(Handle,(LONG *)Stops,NUM_STOPS))
  2265.                 {
  2266.                     struct TermInfo TermInfo;
  2267.  
  2268.                     while(!ParseIFF(Handle,IFFPARSE_SCAN))
  2269.                     {
  2270.                         Chunk = CurrentChunk(Handle);
  2271.  
  2272.                             /* Oops! Some is trying to
  2273.                              * use the phone book file as
  2274.                              * a configuration file.
  2275.                              */
  2276.  
  2277.                         if(Chunk -> cn_ID == ID_CAT)
  2278.                         {
  2279.                             Success = FALSE;
  2280.  
  2281.                             break;
  2282.                         }
  2283.  
  2284.                         if(Chunk -> cn_ID == ID_VERS)
  2285.                         {
  2286.                             if(ReadChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2287.                             {
  2288.                                 if(TermInfo . Version != TermVersion || (TermInfo . Version == TermVersion && TermInfo . Revision > TermRevision))
  2289.                                 {
  2290.                                     if(TermInfo . Version == 2 && TermInfo . Revision == 4)
  2291.                                         UseOld = TRUE;
  2292.  
  2293.                                     if(TermInfo . Version != 3)
  2294.                                         break;
  2295.                                 }
  2296.                             }
  2297.                             else
  2298.                             {
  2299.                                 Error = IoErr();
  2300.  
  2301.                                 break;
  2302.                             }
  2303.                         }
  2304.  
  2305.                         if(Chunk -> cn_ID == ID_WINF)
  2306.                         {
  2307.                             struct WindowInfo Info;
  2308.  
  2309.                             if(ReadChunkBytes(Handle,&Info,sizeof(Info)) == sizeof(Info))
  2310.                             {
  2311.                                 Success = TRUE;
  2312.  
  2313.                                 ReplaceWindowInfo(&Info);
  2314.                             }
  2315.                             else
  2316.                             {
  2317.                                 Error = IoErr();
  2318.  
  2319.                                 Success = FALSE;
  2320.                                 break;
  2321.                             }
  2322.                         }
  2323.                         else
  2324.                         {
  2325.                             if(ConfigChunkType = IsConfigChunk(Chunk -> cn_ID))
  2326.                             {
  2327.                                 if(ReadConfigChunk(Handle,Config,ConfigChunkType,Chunk -> cn_Size,NULL))
  2328.                                 {
  2329.                                     if((TermInfo . Version == 3 && TermInfo . Revision < 6) || TermInfo . Version < 3)
  2330.                                         FixOldConfig(Config,ConfigChunkType,FALSE);
  2331.  
  2332.                                     Success = TRUE;
  2333.                                 }
  2334.                                 else
  2335.                                 {
  2336.                                     Error = IoErr();
  2337.  
  2338.                                     Success = FALSE;
  2339.  
  2340.                                     break;
  2341.                                 }
  2342.                             }
  2343.                         }
  2344.                     }
  2345.                 }
  2346.  
  2347.                 CloseIFF(Handle);
  2348.             }
  2349.  
  2350.             Close(Handle -> iff_Stream);
  2351.         }
  2352.  
  2353.         FreeIFF(Handle);
  2354.     }
  2355.     else
  2356.         Error = IoErr();
  2357.  
  2358.     if(Error)
  2359.         SetIoErr(Error);
  2360.  
  2361.     if(UseOld)
  2362.         return(ReadOldConfig(Name,Config));
  2363.     else
  2364.         return(Success);
  2365. }
  2366.